package com.virtium.vpm.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;


import com.virtium.vpm.dao.DAOFactory;
import com.virtium.vpm.dao.MajorTaskDAO;
import com.virtium.vpm.hibernate.model.MajorTask;

public class MajorTaskManager {
	public static ArrayList<MajorTask> getListMajorTaskByProjectID(List<MajorTask> lsMajorTask,int projetcID){
		ArrayList<MajorTask> arMajorTask = null;
		try{
			arMajorTask = new ArrayList<MajorTask>();
			ListIterator<MajorTask> lt = lsMajorTask.listIterator();
			while(lt.hasNext()){
				MajorTask mj = lt.next();
				if(mj.getProjectId().equals(projetcID))arMajorTask.add(mj);
			}
		}catch(Exception ex){}
		return arMajorTask;
	}
	
	public int addNewMajorTask(MajorTask majorTask){
		
		try{
			MajorTaskDAO majorTaskDAO = DAOFactory.getInstance().getMajorTaskDAO();
			majorTaskDAO.save(majorTask);
		}catch(Exception ex){}
		return majorTask.getId();
	}
	
	public void updateMajorTask(MajorTask majorTask){
		try{
			MajorTaskDAO majorTaskDAO = DAOFactory.getInstance().getMajorTaskDAO();
			majorTaskDAO.update(majorTask);
		}catch(Exception ex){}
	}
	
	public void deleteMajorTask(MajorTask majorTask){
		try{
			MajorTaskDAO majorTaskDAO = DAOFactory.getInstance().getMajorTaskDAO();
			majorTaskDAO.delete(majorTask);
		}catch(Exception ex){}
	}
	
	public ArrayList<MajorTask> getListMajorTaskByProjectID(int projectID){
		ArrayList<MajorTask> arMajorTask = null;
		try{
			arMajorTask = new ArrayList<MajorTask>();
			MajorTaskDAO majorTaskDAO = DAOFactory.getInstance().getMajorTaskDAO();
			arMajorTask.addAll(majorTaskDAO.findByProjectId(projectID));			
		}catch(Exception ex){}
		return arMajorTask;
	}
	
	public ArrayList<MajorTask> getListMajorTaskByUserID(int userID){
		ArrayList<MajorTask> arMajorTask = null;
		try{
			arMajorTask = new ArrayList<MajorTask>();
			MajorTaskDAO majorTaskDAO = DAOFactory.getInstance().getMajorTaskDAO();
			arMajorTask.addAll(majorTaskDAO.findByUserId(userID));			
		}catch(Exception ex){}
		return arMajorTask;
	}
}
